package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired(required = false)
    private IWmChannelService wmChannelService;

    /**
     * 根据名称模糊查询分页列表
     * @param dto
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:sp")//value指名称  notes指备注
    @ApiImplicitParam(name = "dto",value = "查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByPage(@RequestBody ChannelDto dto){
        return wmChannelService.listByPage(dto);
    }

    /**
     * 新增频道
     * @param channel
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody WmChannel channel){
        return wmChannelService.add(channel);
    }

    /**
     * 修改频道
     * @param channel
     * @return
     */
    @PutMapping
    public ResponseResult put(@RequestBody WmChannel channel){
        return wmChannelService.put(channel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable Long id){
        return wmChannelService.delete(id);
    }

    /**
     * 查询所有的频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
